﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TypeWrite.Core;

namespace TypeWrite.Data
{
    public class ContextFactory
    {

        public static TypeWriteDataContext CreateInstance(string connectionStringName)
        {
            if (string.IsNullOrEmpty(connectionStringName))
            {
                TypeWriteDataContext result = new TypeWriteDataContext(Settings.Instance.ConnectionString);
                return result;
            }
            else if (connectionStringName.Contains("="))
            {
                TypeWriteDataContext result = new TypeWriteDataContext(connectionStringName);
                return result;
            }
            else
            {
                TypeWriteDataContext result = new TypeWriteDataContext(ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString);
                return result;
            }
        }

    }
}
